Repository navigation
Keep out CAs from cert manager if allowed only by callback - #11110
mattia-moffa wants to merge 20 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts certificate-chain processing so that intermediate CA certificates are not added to the WOLFSSL_CTX certificate manager when they are only accepted due to an application verify-callback overriding ASN_NO_SIGNER_E or ASN_SELF_SIGNED_E. This preserves the intended “one-time exception” semantics of the callback and prevents unintended trust persistence across connections.
Changes:
- Track the pre-callback verification result (
preCbRet) inProcessPeerCerts()before invokingDoVerifyCallback(). - When the callback clears
ASN_NO_SIGNER_E/ASN_SELF_SIGNED_Eto success, setskipAddCAso the CA is not added to the cert manager.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Jenkins retest this please |
|
6940aa6 to
6bb6321
Compare
cf1d587 to
f58f494
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11110
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
|
Jenkins retest this please |
d53f9a8 to
182289d
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11110
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 5 of 7 in-scope changed file(s) opened by the reviewer; not opened: wolfssl/internal.h, wolfssl/ssl.h
Findings: 4
4 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
09ff855 to
3b50250
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11110
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 3 of 4 in-scope changed file(s) opened by the reviewer; not opened: wolfssl/internal.h
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Lite
| /* Do verify callback */ | ||
| preCbRet = ret; | ||
| ret = DoVerifyCallbackHeldCrl(ssl, args, ret, &heldCrlRet); | ||
| if (ret == 0 && preCbRet != 0) |
There was a problem hiding this comment.
CA whose held CRL error was waived by the verify callback is still added to the shared CertManager · Verify-callback override semantics
The CRL error is held aside in heldCrlRet and ret is set to 0 before the callback runs, so preCbRet is 0. When DoVerifyCallbackHeldCrl waives that error, it clears heldCrlRet and returns 0, so caIsTemp stays 0. The CA then goes through AddCA into the CertManager shared by every connection on the CTX, which is the leak this PR is meant to close.
Suggested fix: Save heldCrlRet before calling DoVerifyCallbackHeldCrl, and set caIsTemp when it was nonzero but the call cleared it and returned 0.
Related known findings (similar but distinct; listed for context, not part of this finding)
- F-14457 (assigned): File/function: both are in the ProcessPeerCerts chain-CA loop, where the callback result gates AddCA. The line numbers differ because the PR shifted the code. Operation: F-14457 is the general case where a callback-cleared error lets AddCA(SSL_CM) run. The candidate is narrower. It is the held-CRL path, where
retis already 0 before the callback runs, sopreCbRetis 0.DoVerifyCallbackHeldCrlthen clearsheldCrlRet, socaIsTempis never set. That path exists in the PR's fix and is not i
There was a problem hiding this comment.
The comment is accurate and worth fixing for consistency (setting caIsTemp whenever heldCrlRet was nonzero going in might be the simpler change).
JacobBarthelmeh
left a comment
There was a problem hiding this comment.
Re-reviewed the changes. They look good, the only adjustment I'd request is the bot's comment about consistency of keeping a CA as temporary if the verify callback overrides the CRL error. I reviewed that comment and believe it is accurate.
- A chain could become longer than the waived CA's path length; the limit was being lost and silently replaced with the maximum - A hash used to authorize delegated OCSP responders was left blank on waived CAs - OCSP responses signed by a waived CA no longer fail to verify - The callback is no longer asked again for every cert below a waived CA in WOLFSSL_SMALL_CERT_VERIFY builds - Unknown-extension callback is now called on waived CAs with an unknown critical extension - Changed waived CA list lifetime to last for the whole connection rather than the Certificate message, so it's still there when a stapled OCSP status arrives
The lookup that searches an OCSP responder's extra signer list was compiled only when OCSP stapling v2 was enabled, while it's now needed for the certs accepted via the verify callback.
d4d486d to
265002f
Compare
|
jenkins retest this please |
Frauschi
left a comment
There was a problem hiding this comment.
The fix works and the new test fails without it; the main gaps are CRL verification against waived CAs and the list never being reset between handshakes. Also, the PR description and the WOLFSSL_TEMP_CA comment in ssl.h still say the list is scoped to one Certificate message, but it now lives for the whole connection.
- Pass the connection's waived CA list down the handshake CRL checks to VerifyCRLE; - Don't put a CRL entry's verdict into the cert manager when a CA waived by the callback verified it; - Carry the waived CA list on WOLFSSL_X509_STORE_CTX so an X509_verify_cert() from the callback resolves the waived CAs too; - Clear it in X509_STORE_CTX_init so a context built by the application only verifies against the store; - Check in test_wolfSSL_X509_STORE_CTX_set0_crls_handshake that the chain CAs go into the waived CA list rather than to the certificate store.
If an OCSP response is signed by a CA waived by the certificate callback, and then it is added to the ctx's certificate manager, it will be trusted by other connections too, but these connections don't trust the signer. So, don't add that OCSP response to the cert manager in this case.
This is needed so that renegotiation and post-handshake auth don't inherit signers from the previous Certificate message. Also prevents duplicate waived CAs by checking before adding.
Move the extra signer (waived CA) lookup in ParseCertRelative after every cert manager lookup, so a trusted CA has priority over an untrusted one that was accepted by the verify callback.
Install the certificate manager's word32 callback alongside the word16 one, as AddCA() does, so an intermediate whose critical extension only the word32 callback accepts no longer fails the handshake.
- Waive only the missing trust anchor, so the handshake succeeds only when the chain CAs act as signers; - Check that the CA the callback waived is not usable as a signer afterwards either; - Add a test case for wolfSSL_clear() that verifies that a reused WOLFSSL object doesn't trust the previous peer's CAs; - Add a test case for a stapled OCSP response whose responder is one of those CAs.
Look up the issuer of a signer being built in the CSRv2 pending pool too (not just in the connection's waived CA list), so the path length imposed by the issuer isn't lost when it's only in the pending pool.
265002f to
e3e0145
Compare
- Guard the wolfSSL_clear() test with !WOLFSSL_NO_TLS12 - Skip the stapled OCSP test when WOLFSSL_ALT_CERT_CHAINS is defined, because it clears the CA error before the callback runs
4f600f1 to
63bb22e
Compare
Frauschi
left a comment
There was a problem hiding this comment.
All points from the last round are addressed.
| #else /* NO_SKID */ | ||
| ca = GetCA(cm, crle->issuerHash); | ||
| #endif /* NO_SKID */ | ||
| if (ca == NULL && extraCa != NULL) { |
There was a problem hiding this comment.
Nothing in the suite covers a CRL issued by a waived CA. A memio case CRL-checking server-chain.pem against certs/crl/ca-int.pem and ca-int2.pem would lock this in.
Description
When an application's verify callback overrides errors on a chain CA cert,
DoVerifyCallback()clearsret.ProcessPeerCerts()then readsret==0as proof that the CA is valid and callsAddCA()to add it to theWOLFSSL_CTXcertificate manager.Instead, the callback allowing a CA is meant to be a one-time exception, specific to that one peer (i.e. the CA shouldn't go to the CTX's cert manager permanently). This fix keeps such a CA on a list owned by that Certificate message. It is still used to verify the rest of the chain, but it never enters the certificate manager, and the list is freed once the message is done.
Fixes zd#22289
Testing